package L1;

import java.io.IOException;
import java.util.Scanner;

public class _096 {
    /**
     * 谁管谁叫爹
     */
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        for (int i=0;i<N;i++){
            int Na = scanner.nextInt();
            int Nb = scanner.nextInt();
            int Sa = falg(Na);
            int Sb = falg(Nb);
            if ((Na%Sb)==0&&(Nb%Sa)==0||(Na%Sb)!=0&&(Nb%Sa)!=0){
                if (Na>Nb){
                    System.out.println("A");
                }else {
                    System.out.println("B");
                }
            }else if ((Na%Sb)==0){
                System.out.println("A");
            }else if ((Nb%Sa)==0){
                System.out.println("B");
            }
        }
    }
    private static int falg(int T){
        int sum=0;
        while (T>0){
            sum += T%10;
            T=T/10;
        }
        return sum;
    }
}
